package queues;

import java.util.ArrayList;

/**
 * @author dhanji@gmail.com (Dhanji R. Prasanna)
 */
public class Queue<I> extends ArrayList<I> {
    private int end = -1;

    public void enqueue(I item) {
        super.add(0, item);
        end++;
    }

    public I dequeue() {
        if (end == -1) return null;

        end--;
        return super.get(end + 1);
    }

    public static void main(String[] args) {
        Queue<String> q = new Queue<String>();
        q.enqueue("Muse");
        q.enqueue("Pearl Jam");
        q.clear();
        q.enqueue("Nirvana");

        System.out.println(q.dequeue());
        assert null == q.dequeue();
    }
}

